﻿#include "ThreeDSurfacePlotSettingData.h"
#include "ScalarBarSettingData.h"
#include "BaseModule/GlobalHelper.h"
namespace pst
{
    ThreeDSurfacePlotSettingData::ThreeDSurfacePlotSettingData(QObject* parent, int id)
        : QObject(parent)
        , m_id(id)
        , m_scalarBarSettingData(nullptr)
        , m_geometrySettingData(nullptr)
        , m_resultDataSettingData(nullptr)
        , m_cubeAxesActorSettingData(nullptr)
    {
    }

    ThreeDSurfacePlotSettingData::~ThreeDSurfacePlotSettingData()
    {
    }

    int ThreeDSurfacePlotSettingData::getID() const
    {
        return m_id;
    }

    void ThreeDSurfacePlotSettingData::setScalarBarSettingData(ScalarBarSettingData* TDSPScalarBarSettingData)
    {
        m_scalarBarSettingData = TDSPScalarBarSettingData;
    }

    ScalarBarSettingData* ThreeDSurfacePlotSettingData::getScalarBarSettingData() const
    {
        return m_scalarBarSettingData;
    }

    void ThreeDSurfacePlotSettingData::setGeometrySettingData(TDSPGeometrySettingData* TDSPGeometrySettingData)
    {
        m_geometrySettingData = TDSPGeometrySettingData;
    }

    TDSPGeometrySettingData* ThreeDSurfacePlotSettingData::getGeometrySettingData() const
    {
        return m_geometrySettingData;
    }

    void ThreeDSurfacePlotSettingData::setResultDataSettingData(TDSPResultDataSettingData* TDSPResultDataSettingData)
    {
        m_resultDataSettingData = TDSPResultDataSettingData;
    }

    TDSPResultDataSettingData* ThreeDSurfacePlotSettingData::getResultDataSettingData() const
    {
        return m_resultDataSettingData;
    }

    //TDSPScalarBarSettingData::TDSPScalarBarSettingData(QObject* parent)
    //    : QObject(parent)
    //{
    //}

    //void TDSPScalarBarSettingData::setScalarBarFontSize(int fontSize)
    //{
    //    m_fontSize = fontSize;
    //}

    //int TDSPScalarBarSettingData::getScalarBarFontSize() const
    //{
    //    return m_fontSize;
    //}

    //void TDSPScalarBarSettingData::setScalarBarMaxValue(double maxValue)
    //{
    //    m_maxValue = maxValue;
    //}

    //double TDSPScalarBarSettingData::getScalarBarMaxValue() const
    //{
    //    return m_maxValue;
    //}

    //void TDSPScalarBarSettingData::setScalarBarMinValue(double minValue)
    //{
    //    m_minValue = minValue;
    //}

    //double TDSPScalarBarSettingData::getScalarBarMinValue() const
    //{
    //    return m_minValue;
    //}

    //void TDSPScalarBarSettingData::setScalarBarAutoRange(bool isAutoRange)
    //{
    //    m_isUseScalarBarAutoRange = isAutoRange;
    //}

    //bool TDSPScalarBarSettingData::getScalarBarAutoRange() const
    //{
    //    return m_isUseScalarBarAutoRange;
    //}

    //void TDSPScalarBarSettingData::setScalarBarIsShowTitle(bool isShowTitle)
    //{
    //    m_isShowTitle = isShowTitle;
    //}

    //bool TDSPScalarBarSettingData::getScalarBarIsShowTitle() const
    //{
    //    return m_isShowTitle;
    //}

    //void TDSPScalarBarSettingData::setScalarBarTitleColor(QColor titleColor)
    //{
    //    m_titleColor = titleColor;
    //}

    //QColor TDSPScalarBarSettingData::getScalarBarTitleColor() const
    //{
    //    return m_titleColor;
    //}

    //void TDSPScalarBarSettingData::setScalarBarFontFamily(QString fontFamily)
    //{
    //    m_fontFamily = fontFamily;
    //}

    //QString TDSPScalarBarSettingData::getScalarBarFontFamily() const
    //{
    //    return m_fontFamily;
    //}

    //void TDSPScalarBarSettingData::setScalarBarTitle(QString title)
    //{
    //    m_title = title;
    //}

    //QString TDSPScalarBarSettingData::getScalarBarTitle() const
    //{
    //    return m_title;
    //}

    //void TDSPScalarBarSettingData::setScalarBarOriginalMinRange(double minValue)
    //{
    //    m_scalarBarMinValueOriginal = minValue;
    //}

    //double TDSPScalarBarSettingData::getScalarBarOriginalMinRange() const
    //{
    //    return m_scalarBarMinValueOriginal;
    //}

    //void TDSPScalarBarSettingData::setScalarBarOriginalMaxRange(double maxValue)
    //{
    //    m_scalarBarMaxValueOriginal = maxValue;
    //}

    //double TDSPScalarBarSettingData::getScalarBarOriginalMaxRange() const
    //{
    //    return m_scalarBarMaxValueOriginal;
    //}

    void ThreeDSurfacePlotSettingData::setCubeAxesActorSettingData(TDSPCubeAxesActorSettingData* cubeAxesActorSettingData)
    {
        m_cubeAxesActorSettingData = cubeAxesActorSettingData;
    }

    TDSPCubeAxesActorSettingData* ThreeDSurfacePlotSettingData::getCubeAxesActorSettingData()
    {
        return m_cubeAxesActorSettingData;
    }

    QDomElement& ThreeDSurfacePlotSettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
    {
        QDomElement _ThreeDSurfacePlotSettingDataRoot = doc->createElement("ThreeDSurfacePlotSettingData");
        QDomAttr idattr = doc->createAttribute("SurfacePlotSettingDataID");
        idattr.setValue(QString::number(m_id));
        _ThreeDSurfacePlotSettingDataRoot.setAttributeNode(idattr);

        if (m_scalarBarSettingData != nullptr)
            m_scalarBarSettingData->writeToProjectFile(doc, &_ThreeDSurfacePlotSettingDataRoot, isdiso);
        if (m_geometrySettingData != nullptr)
            m_geometrySettingData->writeToProjectFile(doc, &_ThreeDSurfacePlotSettingDataRoot, isdiso);
        if (m_resultDataSettingData != nullptr)
            m_resultDataSettingData->writeToProjectFile(doc, &_ThreeDSurfacePlotSettingDataRoot, isdiso);
        if (m_cubeAxesActorSettingData != nullptr)
            m_cubeAxesActorSettingData->writeToProjectFile(doc, &_ThreeDSurfacePlotSettingDataRoot, false, isdiso);

        element->appendChild(_ThreeDSurfacePlotSettingDataRoot);

        return _ThreeDSurfacePlotSettingDataRoot;
    }

    void ThreeDSurfacePlotSettingData::readFromProjectFile(QDomElement* element, bool isdiso)
    {
        m_id = element->attribute("SurfacePlotSettingDataID").toInt();
        auto _ScalarBarSettingDataEle = element->elementsByTagName("ScalarBarSettingData");
        auto _TDSPGeometrySettingDataEle = element->elementsByTagName("TDSPGeometrySettingData");
        auto _TDSPResultDataSettingDataEle = element->elementsByTagName("TDSPResultDataSettingData");
        auto _TDSPCubeAxesActorSettingDataEle = element->elementsByTagName("TDSPCubeAxesActorSettingData");

        if (m_scalarBarSettingData != nullptr)
            m_scalarBarSettingData->readFromProjectFile(&_ScalarBarSettingDataEle.at(0).toElement(), isdiso);
        if (m_geometrySettingData != nullptr)
            m_geometrySettingData->readFromProjectFile(&_TDSPGeometrySettingDataEle.at(0).toElement(), isdiso);
        if (m_resultDataSettingData != nullptr)
            m_resultDataSettingData->readFromProjectFile(&_TDSPResultDataSettingDataEle.at(0).toElement().toElement(), isdiso);
        if (m_cubeAxesActorSettingData != nullptr)
            m_cubeAxesActorSettingData->readFromProjectFile(&_TDSPCubeAxesActorSettingDataEle.at(0).toElement(), false, isdiso);
    }

    TDSPGeometrySettingData::TDSPGeometrySettingData(QObject* parent)
        : QObject(parent)
    {
    }

    void TDSPGeometrySettingData::setGeometryTransparency(int transparency)
    {
        m_transparency = transparency;
    }

    int TDSPGeometrySettingData::getGeometryTransparency() const
    {
        return m_transparency;
    }

    QDomElement& TDSPGeometrySettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
    {
        QDomElement _TDSPGeometrySettingDataRoot = doc->createElement("TDSPGeometrySettingData");

        GlobalHelperInstance->createDomElement(doc, &_TDSPGeometrySettingDataRoot, "Transparency", QString::number(m_transparency));

        element->appendChild(_TDSPGeometrySettingDataRoot);

        return _TDSPGeometrySettingDataRoot;
    }

    void TDSPGeometrySettingData::readFromProjectFile(QDomElement* element, bool isdiso)
    {
        auto _TransparencyNodeList = element->elementsByTagName("Transparency");
        m_transparency = _TransparencyNodeList.item(0).toElement().text().toInt();
    }

    TDSPResultDataSettingData::TDSPResultDataSettingData(QObject* parent)
        : QObject(parent)
    {
    }

    void TDSPResultDataSettingData::setResultDataName(QString resultName)
    {
        m_resultName = resultName;
    }

    QString TDSPResultDataSettingData::getResultDataName() const
    {
        return m_resultName;
    }

    void TDSPResultDataSettingData::setResultDataTransparency(int transparency)
    {
        m_transparency = transparency;
    }

    int TDSPResultDataSettingData::getResultDataTransparency() const
    {
        return m_transparency;
    }

    void TDSPResultDataSettingData::setResultDataScaleFactor(double scaleFactor)
    {
        m_scaleFactor = scaleFactor;
    }

    double TDSPResultDataSettingData::getResultDataScaleFactor() const
    {
        return m_scaleFactor;
    }

    QDomElement& TDSPResultDataSettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
    {
        QDomElement _TDSPResultDataSettingDataRoot = doc->createElement("TDSPResultDataSettingData");

        GlobalHelperInstance->createDomElement(doc, &_TDSPResultDataSettingDataRoot, "ResultName", m_resultName);
        GlobalHelperInstance->createDomElement(doc, &_TDSPResultDataSettingDataRoot, "Transparency", QString::number(m_transparency));
        GlobalHelperInstance->createDomElement(doc, &_TDSPResultDataSettingDataRoot, "ScaleFactor", QString::number(m_scaleFactor));

        element->appendChild(_TDSPResultDataSettingDataRoot);

        return _TDSPResultDataSettingDataRoot;
    }

    void TDSPResultDataSettingData::readFromProjectFile(QDomElement* element, bool isdiso)
    {
        auto _ResultNameNodeList = element->elementsByTagName("ResultName");
        m_resultName = _ResultNameNodeList.item(0).toElement().text();
        auto _TransparencyNodeList = element->elementsByTagName("Transparency");
        m_transparency = _TransparencyNodeList.item(0).toElement().text().toInt();
        auto _ScaleFactorNodeList = element->elementsByTagName("ScaleFactor");
        m_scaleFactor = _ScaleFactorNodeList.item(0).toElement().text().toDouble();
    }

    TDSPCubeAxesActorSettingData::TDSPCubeAxesActorSettingData(QObject* parent)
        :QObject(parent)
    {
    }

    void TDSPCubeAxesActorSettingData::setVisibility(bool isVis)
    {
        m_isVisibility = isVis;
    }

    bool TDSPCubeAxesActorSettingData::getVisibility() const
    {
        return m_isVisibility;
    }

    QDomElement& TDSPCubeAxesActorSettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isFormWindow, bool isdiso)
    {
        QString ElementName = "TDSPCubeAxesActorSettingData";
        if (isFormWindow)
        {
            ElementName = "TDSPCubeAxesActorSettingDataFromWindow";
        }

        QDomElement _TDSPCubeAxesActorSettingDataRoot = doc->createElement(ElementName);

        GlobalHelperInstance->createDomElement(doc, &_TDSPCubeAxesActorSettingDataRoot, "IsVisibility", QString::number(m_isVisibility));

        element->appendChild(_TDSPCubeAxesActorSettingDataRoot);

        return _TDSPCubeAxesActorSettingDataRoot;
    }

    void TDSPCubeAxesActorSettingData::readFromProjectFile(QDomElement* element, bool isFormWindow, bool isdiso)
    {
        auto _IsVisibilityNodeList = element->elementsByTagName("IsVisibility");
        m_isVisibility = (bool)_IsVisibilityNodeList.item(0).toElement().text().toInt();
    }
}
